import React from "react";
import {Modal} from "antd";
import {Flv} from "./Flv";

interface LiveProps {
  liveVideoVisible: boolean
  videoRecord: {
    stream: string,
    vhost: string,
    app: string
  }
  liveVideoClose: (e: React.MouseEvent<HTMLElement>) => void
}

export class Live extends React.Component<LiveProps> {

  showVideo() {
    if (this.props.liveVideoVisible) {
      return <Flv videoId={this.props.videoRecord.stream}
                  videoRef={this.props.videoRecord.stream}
                  videoUrl={`http://${this.props.videoRecord.vhost}:18080/${this.props.videoRecord.app}/${this.props.videoRecord.stream}.flv`}
      />
    }
  }

  render() {
    return <Modal
      title="直播"
      visible={this.props.liveVideoVisible}
      closable={true}
      onCancel={this.props.liveVideoClose}
      destroyOnClose={true}
      footer={null}
    >
      {
        this.showVideo()
      }
    </Modal>
  }

}
